package com.pipi.sso.core.enums;

import com.google.common.collect.Lists;
import com.pipi.sso.core.model.RoleBO;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

/**
 * All rights Reserved, Designed By www.maihaoche.com
 *
 * @Package com.pipi.sso.core.enums
 * @date: 2019/4/15 4:07 PM
 * @Copyright: 2017-2020 www.maihaoche.com Inc. All rights reserved.
 */
public class DormEnums {

    @AllArgsConstructor
    public enum RepairStatusEnum {
        /**
         * <p> (1:待处理 2:已处理 3:已完成) </p>
         */
        PENDING(1, "待处理"),
        processed(2, "已处理"),
//        completed(3, "已完成"),
        ;

        @Getter
        private Integer code;

        @Getter
        private String status;

        public static String getDescByCode(Integer code) {
            if (null != code) {
                RepairStatusEnum[] values = RepairStatusEnum.values();
                for (RepairStatusEnum value : values) {
                    if (value.getCode().equals(code)) {
                        return value.getStatus();
                    }
                }
            }
            return null;
        }
    }

    /**
     * <p> 角色枚举 </p>
     */
    @AllArgsConstructor
    public enum RoleEnum {
        /**
         * <p> 角色枚举 </p>
         */
        ADMIN(1, "admin", "管理员"),
        DORM_ADMIN(2, "dormAdmin", "宿舍管理员"),
        STUDENT(3, "student", "学生");

        @Getter
        private Integer id;

        @Getter
        private String code;

        @Getter
        private String roleName;

        public static RoleBO getRoleById(Integer id) {
            if (null != id) {
                RoleEnum[] values = RoleEnum.values();
                for (RoleEnum value : values) {
                    if (value.getId().equals(id)) {
                        RoleBO role = new RoleBO();
                        role.setRoleId(id);
                        role.setRoleCode(value.getCode());
                        role.setRoleName(value.roleName);
                        return role;
                    }
                }
            }
            return null;
        }

        public static List<RoleBO> getAllRole() {
            List<RoleBO> roleBOList = Lists.newArrayList();
            RoleEnum[] values = RoleEnum.values();
            for (RoleEnum value : values) {
                RoleBO role = new RoleBO();
                role.setRoleId(value.id);
                role.setRoleCode(value.getCode());
                role.setRoleName(value.roleName);
                roleBOList.add(role);
            }
            return roleBOList;
        }
    }
}
